package com.dz.Incubator.service.impl;

import com.dz.Incubator.dao.ServiceContentDao;
import com.dz.Incubator.entity.ServiceContentEntity;
import com.dz.Incubator.service.ServiceContentService;
import com.dz.Incubator.config.Pagination;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ServiceContentServiceImpl implements ServiceContentService {

	private static final Logger logger = LoggerFactory.getLogger(ServiceContentService.class);

    @Autowired
    private ServiceContentDao serviceContentDao;

    @Override
    public ServiceContentEntity insert(ServiceContentEntity serviceContentEntity) {
        serviceContentDao.insert(serviceContentEntity);
        
        return serviceContentEntity;
    }

    @Override
    public ServiceContentEntity update(ServiceContentEntity serviceContentEntity) {
        serviceContentDao.update(serviceContentEntity);
        
        return serviceContentEntity;
    }

    @Override
    public Integer delete(Long id) {
        int ret = serviceContentDao.delete(id);
        return ret;
    }
    
    @Override
    public List<ServiceContentEntity> find(Long[] ids) {
        List<ServiceContentEntity> datas = serviceContentDao.find(ids);
        return datas;
    }

    @Override
    public ServiceContentEntity get(Long id) {
        ServiceContentEntity serviceContentEntity = serviceContentDao.get(id);
        return serviceContentEntity;
    }

    @Override
    public List<ServiceContentEntity> findAll() {
    	List<ServiceContentEntity> datas = serviceContentDao.findAll();
    	return datas;
    }
    
    @Override
    public Pagination findByPagination(Pagination pagination) {
    	List<ServiceContentEntity> datas = serviceContentDao.findByPagination(pagination);
    	pagination.setList(datas);
    	return pagination;
    }
	
	@Override
    public List<ServiceContentEntity> insertBatch(List<ServiceContentEntity> list) {
        int ret = serviceContentDao.insertBatch(list);
        return list;
    }
    
    @Override
    public List<ServiceContentEntity> updateBatch(List<ServiceContentEntity> list) {
        int ret = serviceContentDao.updateBatch(list);
        return list;
    }
    
    @Override
    public List<Long> deleteBatch(Long[] ids) {
        int ret = serviceContentDao.deleteBatch(ids);
        List<ServiceContentEntity>  datas = serviceContentDao.find(ids);
        List<Long> list = new ArrayList<Long>();
        for (ServiceContentEntity data : datas) {
        	list.add(data.getId());
        }
        return list;
    }

    /**
     * 通过服务类型查询服务项目
     * @param serviceId
     * @return
     */
    @Override
    public List<ServiceContentEntity> getServiceInfoByType(Long serviceId) {
        return this.serviceContentDao.getServiceInfoByType(serviceId);
    }

    @Override
    public Map<String,ServiceContentEntity> findPrevAndNext(int id) {
        Map<String,ServiceContentEntity> result = new HashMap<>();
        result.put("prev",this.serviceContentDao.findPrev(id));
        result.put("next",this.serviceContentDao.findNext(id));
        return result;
    }
}